<template>
	<!--编辑标准施工计划  -->
	<view class="flex-col page">
		<view class="flex-col group_2" v-if="showType">
			<view class="flex-col group_3">
				<view class="flex-col section_2">
					<text class="text_1" v-if="previewState == true">合同工期：{{constructionDuration}}个工作日</text>
					<view class="justify-between group_4" ref='groupF'>
						<view class="group_5">
							<text class="text_2">*</text>
							<text class="text_3">开始时间：</text>
						</view>
						<view class="flex-row group_6">
							<picker mode="date" :value="date" @change="bindDateChange">
								<view class="uni-input">
									<text class="text_4">{{date}}</text>
									<image src="../../../static/images/goright.png" class="image_1 image_2" />
								</view>
							</picker>
						</view>
					</view>
				</view>
				<!-- 列表 -->
				<view v-for="(item,i) in planList" :key="i">
					<view class="flex-col section_5">
						<view class="flex-col">
							<!-- 标题 -->
							<view class="justify-between group_13">
								<view class="flex-row">
									<view class="flex-row  text-wrapper_1"><text class="text_13">{{i+1}}</text></view>
									<text class="text_15 text_72"
										v-if="addType ==true">{{item.constructionPlanName}}</text>
								</view>
								<text class="text_17" @click="dele(i)">删除</text>
							</view>
							<view class="justify-between group_15">
								<text class="text_19">初始时长：</text>
								<view class="flex-row ipt-time">
									<input placeholder="0" border="surround" v-model="item.constructionDuration"
										type="number" @change="change" />
									<!-- <input type="submit" value="" v-model="item.constructionDuration"> -->
									<text class="text_21">个工作日</text>
								</view>
							</view>
						</view>
						<view class="justify-between group_16">
							<text class="text_23">是否搭接：</text>
							<view class="flex-row">
								<picker @change="(e)=>{bindPickerChange(e,i)}" :value="item.isLapJoint" :range="array">
									<view class="uni-input u-font-28" v-if="item.isLapJoint ==0">顺接</view>
									<view class="uni-input u-font-28" v-else>搭接</view>
								</picker>
								<image src="../../../static/images/goright.png" class="image_1" />
							</view>
						</view>
						<view class="justify-between group_16" v-if="item.lapTime">
							<text class="text_23">搭接时间长：</text>
							<view class="flex-row">
								<text class="text_25">{{item.lapTime}}</text>
							</view>
						</view>
						<view class="justify-between group_16" v-if="item.isLapJoint !=0">
							<text class="text_23">搭接开始时间：</text>
							<view class="flex-row">
								<picker mode="date" :value="item.planStartTime" @change="(e)=>bindDateChangeDJ(e,i)">
									<view class="uni-input">
										<text class="text_4">{{item.planStartTime}}</text>
										<image src="../../../static/images/goright.png" class="image_1 image_2" />
									</view>
								</picker>
							</view>
						</view>
						<view class="flex-row group_6">


						</view>
					</view>
					<view class="justify-center items-center section_4" v-show="addType">
						<image :src="$IMG_URL+'16557868010275878721.png'" class="image_3" />
						<text class="text_12" @click="addNew(i)">新增计划</text>
					</view>
				</view>
			</view>
			<view class="flex-col items-center text-wrapper_2">
				<text class="text_69" @click="preview" v-if="subShow==true">预览生成标准计划</text>
				<text class="text_69" @click="submit" v-else>确认提交</text>
			</view>
		</view>
		<view v-else>
			<u-empty style="height: 99vh;" mode="data" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<u-overlay :show="uploadloading" @click="uploadloading = false" class="u-flex u-row-center u-col-center">
			<view>
				<u-loading-icon size="50" :textSize="18" text="提交中..." textColor="white" :vertical="true" color="white">
				</u-loading-icon>
			</view>

		</u-overlay>

	</view>
</template>

<script>
	export default {
		components: {},
		data() {
			const currentDate = this.getDate({
				format: true
			})
			return {
				previewState: true,
				planList: [],
				subShow: true,
				date: currentDate,
				array: ['顺接', '搭接'],
				index: 0,
				addType: true,
				constructionDuration: '',
				showType: true,
				dateDJ: currentDate,
				uploadloading: false
			};
		},
		created() {
			this.getdatelist();
			uni.startPullDownRefresh();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		},
		methods: {
			Back() {
				let pageNum = 2
				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[pages.length - pageNum];
				uni.navigateBack({
					success: function() {
						beforePage.$vm.getxjwtlist();
					}

				})
			},
			bindPickerChange(e, i) {
				if (i == 0) {
					uni.showToast({
						icon: "none",
						title: '第一个不可以搭接'
					})
					return;
				}
				this.planList[i].isLapJoint = e.detail.value;
				this.planList[i].planStartTime = this.dateDJ;
			},
			getdatelist() {
				// 获取施工表
				const projectId = uni.getStorageSync('projectId');
				this.$http('common.editstandard', {
					projectId: projectId
				}).then(res => {
					if (res.code == 200) {
						if (res.data.constructionPlanList == null) {
							this.showType = false
						} else {
							this.showType = true
						}
						this.constructionDuration = res.data.constructionDuration;
						this.planList = res.data.constructionPlanList;
						if (res.data.startTime) {
							this.date = res.data.startTime;
						} else {
							this.getDate();
						}

					} else {
						this.showType = false
						uni.showToast({
							title: res.msg,
							icon: "error"
						});

					}
				})
			},
			preview() {
				this.previewState = false;
				this.subShow = false
			},
			loadingclose() {
				this.uploadloading = false
			},
			submit() {
				this.uploadloading = true;
				// for (var i = 0; i < this.planList.length; i++) {
				// 	// console.log(this.planList[i])
				// 	if (this.planList[i].isLapJoint == '1') {
				// 		this.planList[i].planStartTime = this.dateDJ;
				// 	}
				// }
				// console.log(this.planList)
				// planStartTime
				const projectId = uni.getStorageSync('projectId');
				let date = {
					startTime: this.date,
					constructionPlanList: this.planList,
					projectId: projectId
				}
				this.$http('other.Generate', date).then(res => {
					if (res.code == 200) {
						setTimeout(() => {
							this.uploadloading = false;
							let pageNum = 2;
							let pages = getCurrentPages(); // 当前页面
							let beforePage = pages[pages.length - pageNum];
							uni.navigateBack({
								success: function() {
									console.log(beforePage)
									beforePage.$vm.$refs.detail.getJD();
								}

							})
						}, 1000)

					} else {
						uni.showToast({
							title: res.data,
							icon: "error"
						})
					}
				})

			},

			bindDateChange: function(e) {
				this.date = e.detail.value
			},
			bindDateChangeDJ: function(e, i) {
				// console.log(this.planList[i].planStartTime)
				// console.log(this.date)
				// if(this.planList[i].planStartTime<this.date){
				// 	uni.showToast({
				// 		title:'搭接时间不能早于开始时间'
				// 	})
				// 		return;
				// }else{
				this.planList[i].planStartTime = e.detail.value;
				// }

			},
			getDate(type) {
				const date = new Date();
				let year = date.getFullYear();
				let month = date.getMonth() + 1;
				let day = date.getDate();

				if (type === 'start') {
					year = year - 60;
				} else if (type === 'end') {
					year = year + 2;
				}
				month = month > 9 ? month : '0' + month;
				day = day > 9 ? day : '0' + day;
				return `${year}-${month}-${day}`;
			},
			dele(i) {
				// console.log(i);
				/* 删除 */
				this.$http('common.deleteprocedure', {
					constructionPlanId: this.planList[i].constructionPlanId
				}).then(res => {
					if (res.code == 200) {
						this.getdatelist()
					}
				}).catch(err => {

				})
			},
			addNew(index) {
				// 新增
				console.log(index);
				let item = {
					planName: '',
					constructionDuration: '', //初始时长
					isLapJoint: 0,
					planStartTime: '',
				};
				// this.planList.push(item);
				this.planList.splice(index + 1, 0, item);
				this.addType = false;
			}
		},
	};
</script>

<style scoped lang="scss">
	.back-w {
		display: flex;
		flex-direction: row;
		padding-top: 50rpx;
		/* align-items: center; */
		width: 100vw;
		height: 90rpx;
		background-color: #ffffff;
	}

	.f-w-l {
		display: flex;
		flex-direction: row;
		font-weight: bold;
		margin-left: 33%;
	}

	.img {
		display: flex;
		justify-content: space-between;
		width: 200px;
		height: 200px;
	}

	.text_7 {
		margin: 4rpx 0 10rpx;
	}

	.group_11 {
		margin-top: 39rpx;
	}

	.image_3 {

		width: 22rpx;
		height: 22rpx;
	}

	.group_13 {
		padding-bottom: 24rpx;
		border-bottom: solid 1rpx #eeeeee;
	}

	.group_15 {
		padding-top: 22rpx;
	}

	.group_15 .u-input {
		width: 100rpx;
		border: 0 none;
	}

	.image_1 {
		margin-left: 12rpx;
		margin-top: 9rpx;
		width: 24rpx;
		height: 26rpx;
	}

	.text-wrapper_1 {
		flex-shrink: 0;
		// padding-top: 5rpx;
		background-image: url($IMG_URL+'16557868051497130564.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 56rpx;
		height: 40rpx;
	}

	.group_16 {
		margin-top: 39rpx;
	}

	.page {
		background-color: #f6f7f9ff;
		width: 100%;
		overflow-y: auto;
		overflow-x: hidden;
		height: 100vh;
	}

	.group {
		overflow: hidden;
		height: 128rpx;
	}

	.group_2 {
		padding: 0 24rpx 48rpx;
	}

	.section_1 {
		padding-bottom: 5rpx;
		background-color: #ffffff;
	}

	.group_3 {
		padding: 21rpx 0;
	}

	.text-wrapper_2 {
		margin: 18rpx 8rpx;
		padding: 25rpx 0;
		background-color: #1d6aff;
		border-radius: 44rpx;
	}

	.group_1 {
		padding: 56rpx 32rpx 29rpx;
		position: relative;
	}

	.image {
		position: absolute;
		left: 32rpx;
		bottom: 26rpx;
		width: 20rpx;
		height: 36rpx;
	}

	.text {
		color: #333333;
		font-size: 36rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_1 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.group_4 {
		margin-top: 30rpx;
		padding: 30rpx 0 30rpx;
		border-top: solid 1rpx #eeeeee;
	}

	.group_7 {
		padding: 30rpx 0 24rpx;
		border-bottom: solid 1rpx #eeeeee;
	}

	.group_9 {
		padding: 22rpx 0 41rpx;
	}

	.group_20 {
		margin-top: 39rpx;
	}

	.group_5 {
		display: flex;
		align-items: center;
		height: 100%;
	}

	.group_6 {
		display: flex;
		align-items: center;
		height: 100%;
	}

	.group_23 {
		margin-top: 37rpx;
	}

	.text_2 {
		color: #ff371d;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_3 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_4 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.image_2 {
		margin: 3rpx 0 -2rpx 12rpx;
	}

	.text-wrapper {
		padding: 4rpx 0 3rpx;
		flex-shrink: 0;
		background-image: url($IMG_URL+'16557868051497130564.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 56rpx;
		height: 40rpx;
	}

	.text_6 {
		margin-left: 16rpx;
		margin-bottom: 9rpx;
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_5 {
		margin-left: 11rpx;
		color: #ffffff;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.divider {
		background-image: repeating-linear-gradient(90deg, #e6e6e6, #e6e6e6 0%, transparent 0%, transparent 0%);
		height: 1rpx;
	}

	.section_2 {
		padding: 30rpx 24rpx 0;
		background-color: #ffffff;
		border-radius: 16rpx;
	}

	.section_3 {
		margin-top: 20rpx;
		padding-left: 24rpx;
		padding-right: 22rpx;
		background-color: #ffffff;
		border-radius: 16rpx;
	}

	.section_4 {
		margin-top: 20rpx;
		padding: 9rpx 0;
		/* align-self: flex-end; */
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871095991728356.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
		height: 56rpx;
		margin-left: 73%;
	}

	.section_5 {
		margin-top: 24rpx;
		padding: 24rpx 24rpx 24rpx 24rpx;
		background-color: #ffffff;
		border-radius: 16rpx;
	}

	.section_6 {
		margin-top: 20rpx;
		padding: 9rpx 0 17rpx;
		align-self: flex-end;
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871096202535089.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
	}

	.section_7 {
		margin-top: 24rpx;
		padding: 30rpx 22rpx 41rpx 24rpx;
		background-color: #ffffff;
		border-radius: 16rpx;
	}

	.section_8 {
		margin-top: 20rpx;
		padding: 9rpx 0 17rpx;
		align-self: flex-end;
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871096202535089.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
	}

	.section_9 {
		margin-top: 20rpx;
		padding: 9rpx 0 17rpx;
		align-self: flex-end;
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871096202535089.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
	}

	.section_10 {
		margin-top: 20rpx;
		padding: 9rpx 0 17rpx;
		align-self: flex-end;
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871096202535089.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
	}

	.section_11 {
		margin-top: 20rpx;
		padding: 9rpx 0 17rpx;
		align-self: flex-end;
		border-radius: 32rpx;
		background-image: url($IMG_URL+'16557871096202535089.png');
		background-position: 0% 0%;
		background-size: 100% 100%;
		background-repeat: no-repeat;
		width: 188rpx;
	}

	.text_69 {
		color: #ffffff;
		font-size: 32rpx;
		font-family: '.AppleSystemUIFont';
		display: flex;
		align-items: center;
		height: 100%;
		width: 100%;
		justify-content: center;
	}

	.text_12 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';

	}

	.text_27 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_37 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_45 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_53 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_61 {
		margin-left: 10rpx;
		color: #1d6aff;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_23 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_8 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_9 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_17 {
		// margin: 4rpx 0 10rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		height: 100%;
		margin-top: 5rpx;
		color: #ff371d;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_19 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_21 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_25 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_30 {
		margin: 4rpx 0 10rpx;
		color: #ff371d;
		font-size: 24rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_31 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_32 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_33 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_35 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_36 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_15 {
		margin-left: 16rpx;
		// margin-bottom: 9rpx;
	}

	.text_72 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_29 {
		margin-left: 16rpx;
		margin-bottom: 9rpx;
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_34 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_39 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_47 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_55 {
		color: #333333;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_63 {
		color: #999999;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_13 {
		margin-left: -11rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100%;
		color: #ffffff;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.text_28 {
		margin-left: 11rpx;
		color: #ffffff;
		font-size: 28rpx;
		font-family: '.AppleSystemUIFont';
	}

	.ipt-time {}

	.ipt-time input {
		width: 60rpx;
		height: 95%;
		text-align: right;
		margin-right: 10rpx;
	}
</style>
